package com.example.a1018;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {

    private static final int RESULT_OF_ZC = 1;
    private TextView textView3;
    private EditText editTextTextPersonName2;
    private TextView textView4;
    private EditText editTextTextPersonName3;
    private Button button;
    private Button button2;
    String username;
    String password;
    String age;
    String sex;
 String username_input;
 String password_input;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        textView3=(TextView) findViewById(R.id.textView3);
        editTextTextPersonName2=(EditText) findViewById(R.id.editTextTextPersonName2);
        textView4=(TextView) findViewById(R.id.textView4);
        editTextTextPersonName3=(EditText) findViewById(R.id.editTextTextPersonName3);
        button=(Button)findViewById(R.id.button);
        button2=(Button)findViewById(R.id.button2);
    }
    public void dl(View view) {
        username_input=textView3.getText().toString();
        password_input=textView4.getText().toString();

        if (username!=null&&password!=null){
            if (username.equals(username_input)&&password.equals(password_input)){
            Intent intent=new Intent(this,MainActivity.class);
            intent.putExtra("username",username);
            intent.putExtra("password",password);
            intent.putExtra("age",age);
            intent.putExtra("sex",sex);
            startActivity(intent);
        }else {
                Toast.makeText(this, "用户密码错误", Toast.LENGTH_SHORT).show();
            }
        }else{
            Toast.makeText(this,"请先注册",Toast.LENGTH_SHORT).show();

        }
    }

    public void zc(View view) {
        Intent intent=new Intent(this,zcActivity.class);
        startActivityForResult(intent,RESULT_OF_ZC);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable  Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==RESULT_OF_ZC)
        {
            if (resultCode== Activity.RESULT_OK){
                username=data.getStringExtra("username");
                password=data.getStringExtra("password");
                age=data.getStringExtra("age");
                sex=data.getStringExtra("sex");
                button.setText(username);
                button2.setText(password);

            }
        }

    }
}